import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tuple/tuple.dart';
import 'package:yjl_flutter_test/flutter/listview_paging/paging_widget.dart';
import 'package:yjl_flutter_test/flutter/path/path_test.dart';
import 'package:yjl_flutter_test/flutter/screen_adapter.dart';
import 'package:yjl_flutter_test/flutter/textfield/text_field_demo.dart';
import 'package:yjl_flutter_test/flutter/volume_test.dart';
import 'package:yjl_flutter_test/flutter/widget/layout_builder_test.dart';

import 'flow_widget.dart';
import 'flutter/list_wheel_test.dart';
import 'flutter/router/enter_exit_route.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
      // routes: <String, WidgetBuilder>{
      //   '/flow': (_) => FlowTestPage(),
      // },
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  var routerTuple = <Tuple2<String, Widget>>[
    Tuple2('去Flow页面', FlowTestPage()),
    Tuple2('去Volume音量测试页面', VolumeTestWidget()),
    Tuple2('去ListWheel页面', ListWheelViewPortDemo()),
    Tuple2('去屏幕适配页面', ScreenAdapter()),
    Tuple2('去LayoutBuilder页面', LayoutBuilderTest()),
    Tuple2('按楼层分页加载', PagingWidget()),
    Tuple2('path test', PathTest()),
    Tuple2('软键盘测试', TextFieldDemo()),
  ];

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: ListView.builder(
        itemBuilder: (ctx, index) {
          return child(routerTuple[index].item1, routerTuple[index].item2);
        },
        itemCount: routerTuple.length,
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  Widget child(String title, Widget routerWidget) {
    return CupertinoButton(
        child: Container(
          width: double.infinity,
          height: 60,
          color: Color.fromRGBO(Random().nextInt(256), Random().nextInt(256),
              Random().nextInt(256), 0.2),
          padding: EdgeInsets.only(left: 20),
          alignment: Alignment.centerLeft,
          child: Text(title),
        ),
        onPressed: () {
          Navigator.push(context,
              EnterExitRoute(exitPage: this.widget, enterPage: routerWidget));
        });
  }
}
